---
description: "Reference for Nitric's Go library - Retrieves the value from a version of a secret."
---

# Go - Secret.AccessVersion()

<Note>
  This is reference documentation for the Nitric Go SDK. To learn about Secrets
  in Nitric start with the [Secrets docs](/secrets).
</Note>

Retrieves the value from a version of a secret.

```go
import (
  "context"
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
  "github.com/nitrictech/go-sdk/nitric/secrets"
)

func main() {
  secret := nitric.NewSecret("secret-name").Allow(secrets.SecretAccess)

  value, err := secret.AccessVersion(context.TODO(), "latest")
  if err != nil {
    return
  }

  fmt.Println(value.AsString())

  nitric.Run()
}
```

## Parameters

<Properties>
  <Property name="ctx" required type="context">
    The context of the call, used for tracing.
  </Property>
  <Property name="version" required type="string">
    The ID of the secret version to access
  </Property>
</Properties>

## Examples

### Access the latest version of a secret

```go
import (
  "context"
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
  "github.com/nitrictech/go-sdk/nitric/secrets"
)

func main() {
  secret := nitric.NewSecret("secret-name").Allow(secrets.SecretAccess)

  value, err := secret.AccessVersion(context.TODO(), "latest")
  if err != nil {
    return
  }

  fmt.Println(value.AsString())

  nitric.Run()
}
```

### Access a specific version of a secret

```go
import (
  "context"
  "fmt"

  "github.com/nitrictech/go-sdk/nitric"
  "github.com/nitrictech/go-sdk/nitric/secrets"
)

func main() {
  secret := nitric.NewSecret("secret-name").Allow(secrets.SecretAccess)

  version, err := secret.AccessVersion(context.TODO(), "the-version-id")
  if err != nil {
    fmt.Println(err)
    return
  }

  fmt.Println(version.AsString())

  nitric.Run()
}
```
